<div class="grid_12" style="margin-bottom: 40px;">
    <fieldset>
        <legend>Sim đã bán</legend>
        <table> 
            <tr>
                <td><input type="text" name="date_new" id="date_new" readonly="readonly" value="<?php echo date('d/m/Y', strtotime('-1 month')) . ' đến ' . date('d/m/Y') ?>" style="margin-bottom: 10px;width:200px;text-align: center;" /></td>
                <td style="padding: 5px"><img src="<?php echo STATIC_DOMAIN ?>/images/simsodep/date.png" width="26" style="margin-bottom: -4px"></td>
            </tr>
        </table>
        <div id="demo" class="clearfix">
            <table class="display" id="dataTable"> 
                <thead> 
                    <tr> 
                        <th>Số điện thoại</th> 
                        <th>Mạng</th> 
                        <th>Nhóm sim</th> 
                        <th>Đại lý</th> 
                        <th>Ngày</th> 
                        <th>Giá</th> 
                        <th>Tình trạng</th>
                    </tr> 
                </thead>
                <tbody>
                    <?php foreach ($sim as $s): ?>
                        <tr class="<?php echo ($s['status'] == 1) ? 'gradeA' : 'gradeX' ?>"> 
                            <td class="center"><?php echo $s['phone'] ?></td> 
                            <td class="center"><?php echo $s['network_name'] ?></td>
                            <td class="center"><?php echo $s['group_name'] ?></td>
                            <td class="center"><?php echo $s['city_name'] ?></td>
                            <td class="center"><?php echo date('d-m-y', $s['modified']) ?></td> 
                            <td class="center"><span style="color: red"><?php echo number_format($s['price_update'], 0, '.', '.') ?> VNĐ</span></td>
                            <td class="center">
                            <?php 
                                switch ($s['status']) {
                                    case 0 : 
                                        echo 'Đã bán';
                                        break;
                                    case 1 :
                                        echo 'Còn hàng';
                                        break;
                                }
                            ?>
                        </td> 
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </fieldset>

</div>

<script type="text/javascript">
    $(function() {
        var xhr;
        $("#date_new").DatePicker({
            format: 'd/m/Y',
            date: ['<?php echo date('d/m/Y', strtotime('-1 month')); ?>', '<?php echo date('d/m/Y'); ?>'],
            current: '<?php echo date('d/m/Y') ?>',
            calendars: 2,
            mode: 'range',
            starts: 1,
            position: 'bottom',
            locate: 'week',
            onChange: function(formated, dates) {
                $('#date_new').val(formated.join(' đến '));
                if ($('#closeOnSelect input').attr('checked')) {
                    $('#date_new').DatePickerHide();
                }
                filterResult('new', formated[0], formated[1]);
            }
        });
        
        function filterResult(type, startdate, enddate) {
            type = (type == 'new') ? 'new' : 'ordered';
            (xhr) && (xhr.abort());
            xhr = $.ajax({
                url : '<?php echo site_url('admin/dashboard/load') ?>',
                dataType : 'html',
                type : 'POST',
                data : {
                    type : type,
                    start : startdate,
                    end : enddate
                },
                success : function(html) {
                    $("#demo").html(html);
                }
            });
        }

    });
//    $( "#Date" ).datepicker();
//    });
</script>